package com.woniuxy.ams.controller;

import com.woniuxy.ams.entity.DailyAssessDetails;
import com.woniuxy.ams.entity.Detail;
import com.woniuxy.ams.entity.ResultEntity;
import com.woniuxy.ams.service.DetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/dayAssessDetail")
public class DetailController {
    DetailService detailService;
    @Autowired(required = false)
    public void setDetailService(DetailService detailService) {
        this.detailService = detailService;
    }

    /**
     * 新增日考核明细
     * @param detail
     * @return
     */
    @RequestMapping("/insert")
    public ResultEntity<Integer> insertDetail(@RequestBody Detail detail){
        int code = detailService.insert(detail);
        if (code!=0){
            return new ResultEntity<>(200,"新增成功！",code);
        }else {
            return new ResultEntity<>(400,"新增失败！",code);
        }
    }

    /**
     * 删除日考核明细
     * @param id
     * @return
     */
    @RequestMapping("/delete")
    public ResultEntity<Integer> deleteDetail(@RequestParam("id") int id){
        int code = detailService.delete(id);
        if (code!=0){
            return new ResultEntity<>(200,"删除成功！",code);
        }else {
            return new ResultEntity<>(400,"删除失败！",code);
        }
    }

    /**
     * 查询日考核明细findByIdStr
     */
    @RequestMapping("/findAllClause")
    public ResultEntity<List<Detail>> findAllDetail(){
        List<Detail> allDetail = detailService.findAll();
        return new ResultEntity<>(200,"查询成功!",allDetail);
    }
    @RequestMapping("/findById")
    public ResultEntity<List<Detail>> findByIdStr(@RequestParam("idStr") String idStr){
        List<Detail> allDetail = detailService.findByIdStr(idStr);
        return new ResultEntity<>(200,"查询成功!",allDetail);
    }

    @RequestMapping("/findDetailById")
    public ResultEntity<List<Detail>> findByDailyAssessDetail(@RequestBody DailyAssessDetails dailyAssessDetails){
        String projectId = dailyAssessDetails.getProjectId();
        List<Detail> byIdStr = detailService.findByIdStr(projectId);
        return new ResultEntity<>(200,"查询成功!",byIdStr);
    }

    /**
     * 修改 动态修改 按条件修改
     */
    @RequestMapping("/update")
    public ResultEntity<Integer> updateDetail(@RequestBody  Detail clause){
        int code =  detailService.update(clause);
        if (code!=0){
            return new ResultEntity<>(200,"修改成功！",code);
        }else {
            return new ResultEntity<>(400,"修改失败！",code);
        }
    }



}
